package com.bdqn.t350.servlet.echarts;

import com.alibaba.fastjson.JSON;
import com.bdqn.t350.entity.PieEntity;
import com.google.gson.stream.JsonToken;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/echarts/PieServlet")
public class PieServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PieEntity pieEntity1 = new PieEntity("衣服", 100);
        PieEntity pieEntity2 = new PieEntity("裤子", 200);
        PieEntity pieEntity3 = new PieEntity("帽子", 300);
        PieEntity pieEntity4 = new PieEntity("袜子", 400);
        List<PieEntity> list = new ArrayList<>();
        list.add(pieEntity1);
        list.add(pieEntity2);
        list.add(pieEntity3);
        list.add(pieEntity4);
        response.getWriter().print(JSON.toJSONString(list));
    }
}
